<%@page import="cn.lily.inst.web.security.XSSFilter"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="cn.lily.com.cryptor.cipher.RSACiphers"%>
<%@ page import="cn.lily.com.configure.util.ESBSetting"%>
<%@ page import="cn.lily.inst.web.frames.FrameConfig" %>
<%

session.invalidate();
Cookie[] cookies=request.getCookies();
if(null!=cookies){
    for(int i=0;i<cookies.length;i++){
        if("JSESSIONID".equalsIgnoreCase(cookies[i].getName())){
            cookies[i].setMaxAge(0);
            response.addCookie(cookies[i]);
        }
    }
} 

response.addHeader("Cache-Control", "no-store");
response.addHeader("Pragma", "no-cache");

String contextPath = request.getContextPath();
FrameConfig.setContextPath(contextPath);

String modulus = RSACiphers.getModulus();
String exponent = RSACiphers.getExponent();

String  msg  ="";
if(request.getParameter("msg")!=null && request.getParameter("msg").length()>0){
  msg = request.getParameter("msg");
  if("1".equals(msg)){
    msg = "登录用户或密码错误，请检查！" ;
  }else if("2".equals(msg)){
    msg = "用户状态为不可用！" ;
  }
  
}

msg = XSSFilter.xssFilter(msg);

%>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="pragma" content="no-cache"> 
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate"> 
    <meta http-equiv="expires" content="0">
    <title>登录</title>
    <link rel="stylesheet" href="/<%=ESBSetting.getString("appCode")%>/public/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="/<%=ESBSetting.getString("appCode")%>/public/style/skin_layui/login.css"/>
    <link rel="stylesheet" href="/<%=ESBSetting.getString("appCode")%>/public/font/awesome_3.2/css/font-awesome.css">
    <script src="/<%=ESBSetting.getString("appCode")%>/public/js/develop/security/security.js"></script>
    <script src="/<%=ESBSetting.getString("appCode")%>/public/js/common/jquery-1.11.2.min.js"></script>
    <script src="/<%=ESBSetting.getString("appCode")%>/public/js/base/Base.js"></script>
    <!--[if IE 7]> <link rel="stylesheet" href="/<%=ESBSetting.getString("appCode")%>/public/font/awesome_3.2/css/font-awesome-ie7.min.css"> <![endif]-->
    <style type="text/css">
      body {
        background: url("/<%=ESBSetting.getString("appCode")%>/public/images/skin_layui/login/bg.png");
      }
      .footer-wrap {
        margin-top: 0;
      }
      .login {
        min-height: 650px;
      }
    </style>
  </head>
  <body>
    <div class="login">
      <div class="login-warp">
        <div class="login-logo">
          <img src="/<%=ESBSetting.getString("appCode")%>/public/images/skin_layui/logo/logo2.png"/>
        </div>
        <div class="body">
          <div style="color: red;" align="center" class="prompt">
            <span id="promptContent"></span>
          </div>
          <form class="layui-form" id="loginForm" name="loginForm" method="post" action="<%=FrameConfig.getHomePage()%>">
            <div class="layui-form-item">
              <label class="layui-form-label">
                <i class="icon-user"></i>
              </label>
              <div class="layui-input-block">
                <input type="text" name="username" id="loginUsername" lay-verify="user" placeholder="请输入用户名" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">
                <i class="icon-lock"></i>
              </label>
              <div class="layui-input-block">
                <input type="password" name="password" id="loginPassword" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">
                <i class="icon-briefcase"></i>
              </label>
              <div class="layui-input-block">
                <input type="text" name="yanzheng" id="loginCode" lay-verify="veri" placeholder="请输入验证码" autocomplete="off" class="layui-input" style="width:250px;">
                <img src="/<%=ESBSetting.getString("appCode")%>/imageCodeService" align="absmiddle" title="点击更换验证码" onclick="changeValCode(this)" />           
              </div>
            </div>
            <div class="layui-form-item">
              <button class="layui-btn" lay-submit="" lay-filter="demo1" type="submit">登 陆</button>
            </div>
          </form>
        </div>
        <div class="foot">
          <a href="javascript:;"><%=msg%></a>
        </div>
      </div>
    </div>
    <script src="/<%=ESBSetting.getString("appCode")%>/public/plugins/layui/layui.all.js"></script>
    <script type="text/javascript">
    
       layui.use(['layer', 'element', 'form' ], function () {
    	
        var form = layui.form,
        layer = layui.layer;
        
        //自定义验证规则
        form.verify({
          user: function (value) {
            value = value.replace(/\s+/g, "");
            if (value == null || value == "") {
              return '用户名不允许为空哟!';
            }
            if (value.indexOf("'") != -1) {
              return '用户名不允许输入特殊符号哟!';
            }
            
            value = stripscript(value);
            
            $("#loginUsername").val(value);
          },
          pass: function (password) {
        	 
            password = password.replace(/\s+/g, "");
            if (password == null || password == "") {
              return '密码不允许为空哟!';
            }
            if (password.indexOf("'") != -1) {
              return '密码不允许输入特殊符号哟!';
            }
            
            var startTime = new Date().getTime() + "";         
            var randk = startTime.substring(startTime.length-6);
            
            password = pwscript(password);
            
            password = randk + password ;
            
            var modulus = Yacon.def.modulus;
            var exponent = Yacon.def.exponent;      
     		
            var key = RSAUtils.getKeyPair(exponent, '', modulus);
            var pwd = RSAUtils.encryptedString(key, password);	
            
            $("#loginPassword").val(pwd);

          },
          veri: function (value) {
              value = value.replace(/\s+/g, "");
              if (value == null || value == "") {
                return '验证码不允许为空哟!';
              }
              if (value.indexOf("'") != -1) {
                return '验证码不允许输入特殊符号哟!';
              }
              
              value = stripscript(value);
              
              $("#loginCode").val(value);
              
          }
          
        });
        
        //监听提交
        form.on('submit(demo1)', function (data) {      
          //layer.alert(JSON.stringify(data.field), {title: '提交信息'});
        });
      });
      
      //修改验证码
      function changeValCode(obj){  
    	  obj.src = "/<%=ESBSetting.getString("appCode")%>/imageCodeService?random="+Math.random();   
      }
      
      function stripscript(s) {
  		var pattern = new RegExp("[%`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]") ;
  		var rs = "";
  		if(s.length > 0){
  			for (var i = 0; i < s.length; i++) {
  				rs = rs + s.substr(i, 1).replace(pattern, '');
  			}
  		}
  		return rs;
  	 }
      
     function pwscript(s) {
  		var pattern = new RegExp("[%`~!@#$^&*()=|{}':;',\\[\\].?~！@#￥……&*（）——|{}【】‘；：”“。，、？]") ;
  		var rs = "";
  		if(s.length > 0){
  			for (var i = 0; i < s.length; i++) {
  				rs = rs + s.substr(i, 1).replace(pattern, '');
  			}
  		}
  		return s ;
  	 }
     
     function AntiSqlValid(oField){
         var re= /select|update|having|delete|exec|count|’|"|=|;|>|<|%/i;
         if (re.test(oField))
         {
           return false;
    	 } 
         return true;
   	 }
     
     //高度回调
     $(function(){    	 
    	 var winHeight = $(window).height();  	 
    	 var platHt = (winHeight - 430 -180)/2;  	
    	 $(".login").css("margin-top",platHt+"px"); 	 
     });
     
    </script>
  </body>
</html>
